package main

import "fmt"

func checkInclusion(s1 string, s2 string) bool {
	window, need := make(map[byte]int), make(map[byte]int)
	for i := 0; i < len(s1); i++ {
		need[s1[i]]++
	}
	left, right := 0, 0
	valid := 0
	for right < len(s2) {
		c := s2[right]
		if _, ok := need[c]; ok {
			window[c]++
			if window[c] == need[c] {
				valid++
			}
		}
		right++
		for right-left >= len(s1) {
			if valid == len(need) {
				return true
			}
			t := s2[left]
			if _, ok := need[t]; ok {
				if window[t] == need[t] {
					valid--
				}
				window[t]--
			}
			left++
		}
	}
	return false
}

func main() {
	inclusion := checkInclusion("ab", "eidboaoo")
	fmt.Println(inclusion)
}
